package com.pactera.mavenweb.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.pactera.mavenweb.dao.UserGroupDao;
import com.pactera.mavenweb.entity.UserGroup;
import com.pactera.mavenweb.service.UserGroupService;

@Service("userGroupService")
public class UserGroupServiceImpl implements UserGroupService {
	
	/**
	 * 注入dao
	 */
	@Resource(name = "userGroupDao")
	private UserGroupDao userGroupDao;
	
//	@Override
	public int saveUserGroups(List<UserGroup> userGroups) {
		try {
			for (UserGroup userGroup : userGroups) {
				userGroupDao.saveUserGroup(userGroup);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return 0;
	}
	
//	@Override
	public List<UserGroup> getAllUserGroup() {
		return userGroupDao.queryAll();
	}
	
//	@Override
	public void addUserGroup(UserGroup userGroup) {
		userGroupDao.saveUserGroup(userGroup);
	}
	
//	@Override
	public boolean delUserGroup(int id) {
		
		userGroupDao.delete(id);
		
		return true;
	}
	
//	@Override
	public void updateUserGroup(UserGroup userGroup) {
		userGroupDao.update(userGroup);
	}
	
//	@Override
	public UserGroup getUserGroup(String id) {
		return userGroupDao.queryById(id);
	}
	
//	@Override
	public List<UserGroup> getUsersFromGroupId(int groupId) {
		String hql = "from UserGroup where group_id = ?";
		Object[] idArray = {groupId};
		
		return userGroupDao.queryForList(hql, idArray);
	}
}